
import { Menu,Icon } from '@/api';

// 加载
const load_menu_list = async (context, payload) => {
    let { status,msg, data } = await Menu.all(payload);
    if (status) {
        context.commit("UPDATE_MENU", data);
    }
    return {status,msg,data}
}

const load_icon = async (context, payload) => {
    let { status,msg, data,total,icons } = await Icon.list(payload);
    if (status) {
        context.commit("UPDATE_ICON", data);
    }
    return {status,msg,data,total}
}

const insert_menu=async (context,payload)=>{
    let {status,msg,data}=await Menu.add(payload);
    if(status){
        context.commit("INSERT_MENU",{...data,...payload})
    }
    return {status,msg,data}
}

const insert_oper=async (context,payload)=>{
    let {status,msg,data}=await Menu.add_oper(payload);
    if(status){
        context.commit("INSERT_MENU",{...data,...payload})
    }
    return {status,msg,data}
}


// 修改
const edit_menu=async (context,payload)=>{
    let {status,msg}=await Menu.edit(payload[0],payload[1]);
    if (status) {
        context.commit('EDIT_MENU', payload);
    }
    return {status,msg}
}

const edit_oper=async (context,payload)=>{
    let {status,msg}=await Menu.edit_oper(payload[0],payload[1]);
    if (status) {
        context.commit('EDIT_MENU', payload);
    }
    return {status,msg}
}

const edit_icons=async (context,payload)=>{
    console.log(payload);
    let {status,msg}=await Menu.edit_icon(payload[0],payload[1]);
    if (status) {
        context.commit('EDIT_MENU', payload);
    }
    return {status,msg}
}

const remove_menu=async (context, payload) => {
    let { status, msg } = await Menu.remove(payload[0],payload[1]);
    if (status) {
        context.commit("REMOVE_MENU", payload);
    }
    return { status, msg }
}

const remove_oper=async (context, payload) => {
    let { status, msg } = await Menu.remove_oper(payload);
    if (status) {
        context.commit("REMOVE_OPER", payload);
    }
    return { status, msg }
}

export default {
    load_menu_list,
    load_icon,
    insert_menu,
    insert_oper,
    edit_menu,
    edit_oper,
    edit_icons,
    remove_menu,
    remove_oper
}